<template>
  <div>
    <el-table
      :data="manageList"
      style="width: 100%"
      row-key="id"
      border
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
    >
      <el-table-column prop="id" label="角色编号"> </el-table-column>
      <el-table-column prop="username" label="管理员名称"> </el-table-column>
      <el-table-column prop="rolename" label="所属角色"> </el-table-column>
      <el-table-column label="状态">
        <template slot-scope="scope">
          <div>
            <el-button type="success" v-if="scope.row.status == 1"
              >启 用</el-button
            >
            <el-button type="danger" v-else>禁 用</el-button>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <div>
            <el-button type="primary" plain @click="edit(scope.row.uid)">
              编 辑</el-button
            >
            <v-del @del="del(scope.row.uid)"></v-del>
          </div>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页器 -->
    <el-pagination
      background
      layout="prev, pager, next"
      :total="manageTotal"
      :page-size="manageSize"
      @current-change="change"
    >
      <!-- page-size 每一页的条数 -->
    </el-pagination>
  </div>
</template>
<script>
import { mapGetters, mapActions } from "vuex";
import { successAlert, warningAlert } from "../../../util/alert";
import { manageDel } from "../../../request/api";
export default {
  props: [],
  components: {},
  data() {
    return {};
  },
  computed: {
    ...mapGetters({
      manageList: "manage/list",
      manageTotal: "manage/total",
      manageSize: "manage/size",
    }),
  },
  methods: {
    ...mapActions({
      reqManageList: "manage/reqChangeList",
      reqManageTotal: "manage/reqChangeTotal",
      reqManagePage: "manage/reqChangePage",
    }),
    //封装版本删除
    del(uid) {
      manageDel({ uid: uid }).then((res) => {
        if (res.data.code == 200) {
          //删除成功弹窗
          successAlert(res.data.msg);
          //重新请求列表数据
          this.reqManageList();
          //重新请求总条数
          this.reqManageTotal();
        } else {
          //删除失败弹窗
          warningAlert(res.data.msg);
        }
      });
    },
    //编辑
    edit(uid) {
      this.$emit("edit", uid);
    },
    //当页码发生变化
    change(num) {
      this.reqManagePage(num);
    },
  },
  mounted() {
    //每一次进去都将状态层的当前页码数变成1
    this.reqManagePage(1);
    //请求总条数
    this.reqManageTotal();
  },
};
</script>
<style scoped>
</style>